#include "ConfigGroup.h"

namespace JMTools
{
	namespace Config
	{
		ConfigGroup::ConfigGroup()
		{
			this->name = "Default";
		}

		ConfigGroup::ConfigGroup(std::string name)
		{
			this->name = name;
		}
	
		ConfigGroup::~ConfigGroup()
		{
		}

		std::string ConfigGroup::getName()
		{
			return this->name;
		}

		void ConfigGroup::setName(std::string name)
		{
			this->name = name;
		}

		std::map<std::string,std::list<std::string> > ConfigGroup::getData()
		{
			return this->data;
		}

		std::string ConfigGroup::getValue(std::string key)
		{
			if (this->data.find(key)==this->data.end())
				return "";
			else
				return this->data.find(key)->second.front();
		}
	
		std::list<std::string> ConfigGroup::getList(std::string key)
		{
			if (this->data.find(key)==this->data.end())
				return (*new std::list<std::string>());
			else
				return this->data.find(key)->second;
		}

		void ConfigGroup::add(std::string key, std::string value)
		{
			std::list<std::string> data;
			if (this->data.find(key)==this->data.end())
			{
				data.push_back(value);
				this->data.insert(std::pair<std::string,std::list<std::string> >(key,data));
			}
			else
			{
				std::map<std::string,std::list<std::string> >::iterator it = this->data.find(key);
				data = it->second;
				data.push_back(value);
				this->data.erase(it);
				this->data.insert(std::pair<std::string,std::list<std::string> >(key,data));
			}
		}

	}
}
